import moment from 'moment'

export default {
	xLabelFormat: function(v) {
		const dateObj = new Date(v)
		const hours = dateObj.getHours() > 10 ? dateObj.getHours() : '0' + dateObj.getHours()
		const minutes = dateObj.getMinutes() < 10 ? dateObj.getMinutes() + '0' : dateObj.getMinutes()
		const UnixTimeToDate = hours + ':' + minutes
		return UnixTimeToDate
	},
	markPointTooltipFormat: function(v) {
		if(Object.prototype.toString.call(v) == '[object Object]') {
			let data = v.data.name.split('|');
			var str = ''
			for(var i=0;i<data.length;i++) {
				str += '<div>' + data[i] + '</div>'
			}
			return `
				<div>
					<div>${moment(v.data.coord[0]).format('YYYY-MM-DD HH:mm:ss')}</div>
					<div>当前值：${(v.data.coord[1]).toFixed(2)}</div>
					${str}
				</div>
			`
		} else if(v[0].name) {
			let data = v[0].data.name.split('|');
			var str = ''
			for(var i=0;i<data.length;i++) {
				str += '<div>' + data[i] + '</div>'
			}
			return `
				<div>
					<div>${moment(v[0].data.value[0]).format('YYYY-MM-DD HH:mm:ss')}</div>
					<div>当前值：${(v[0].data.value[1]*1).toFixed(2)}</div>
					${str}
				</div>
			`
		} else {
			return `
				<div>
					<div>${moment(v[0].data.value[0]).format('YYYY-MM-DD HH:mm:ss')}</div>
					<div>当前值：${(v[0].data.value[1]*1).toFixed(2)}</div>
				</div>
			`
		}
		
	}
}